﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using AdventureWorksLT.Views.Customers.ViewModels;
using System.Linq;
using System.Windows.Media;
using System.Windows.Printing;
using System.Collections.Generic;
using System.IO;
namespace AdventureWorksLT.Views.Customers.WorkWith
{
    public partial class CustomerWorkWithGrid : Page
    {

        public CustomerWorkWithGrid()
        {
            CustomersViewModel.DashLoad_PK = 0;
            //LocalizationManager.Manager = new WorkWith.CustomLocalizationManager();
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {


        }



        public static int CCustomerID;
        int _dashLoadPk;
        private void ObtainCustomerID()
        {
            if (CustomersDataGrid.SelectedItem != null)
            {
                string a = CustomersDataGrid.SelectedItem.ToString();
                int i = a.IndexOf(":") + 1;
                a = a.Substring(i);
                int.TryParse(a, out _dashLoadPk);
                CustomersViewModel.DashLoad_PK = _dashLoadPk;
                CCustomerID = _dashLoadPk;
            }
        }

        private static void Failed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            MessageBox.Show("Exception " + e.Exception);
        }

        private void DashboardButton_Click(object sender, RoutedEventArgs e)
        {
            ObtainCustomerID();
            if (CCustomerID > 0)
            {
                Uri target = new Uri("/Dashboard/DashboardP?CustomerID=" + CustomersViewModel.DashLoad_PK, UriKind.Relative);
                NavigationService.NavigationFailed += new NavigationFailedEventHandler(Failed);
                if (NavigationService != null) NavigationService.Navigate(target);
            }
        }

        private void GoToCustomerAddressButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ObtainCustomerID();
            if (CCustomerID > 0)
            {
                Uri target = new Uri("/Customers/Controls/CustomerAddressControl?CustomerID=" + CustomersViewModel.DashLoad_PK, UriKind.Relative);
                NavigationService.NavigationFailed += new NavigationFailedEventHandler(Failed);
                if (NavigationService != null) NavigationService.Navigate(target);
            }
        }
        private void GoToSalesOrderHeaderButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ObtainCustomerID();
            if (CCustomerID > 0)
            {
                Uri target = new Uri("/Customers/Controls/SalesOrderHeaderControl?CustomerID=" + CustomersViewModel.DashLoad_PK, UriKind.Relative);
                NavigationService.NavigationFailed += new NavigationFailedEventHandler(Failed);
                if (NavigationService != null) NavigationService.Navigate(target);
            }
        }
        private void GoToCustomerButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ObtainCustomerID();
            Uri target = new Uri("/Customers/Controls/CustomerControl?CustomerID=" + CustomersViewModel.DashLoad_PK, UriKind.Relative);
            NavigationService.NavigationFailed += new NavigationFailedEventHandler(Failed);
            if (NavigationService != null) NavigationService.Navigate(target);
        }


    }
}

